//preload images
var orn_0 = new Image();
orn_0.src = "pngs/orn/0.png";
var orn_1 = new Image();
orn_1.src = "pngs/orn/1.png";
var orn_2 = new Image();
orn_2.src = "pngs/orn/2.png";
var orn_3 = new Image();
orn_3.src = "pngs/orn/3.png";
var orn_4 = new Image();
orn_4.src = "pngs/orn/4.png";
var orn_5 = new Image();
orn_5.src = "pngs/orn/5.png";
var orn_6 = new Image();
orn_6.src = "pngs/orn/6.png";
var orn_7 = new Image();
orn_7.src = "pngs/orn/7.png";
var orn_8 = new Image();
orn_8.src = "pngs/orn/8.png";
var orn_9 = new Image();
orn_9.src = "pngs/orn/9.png";
//
var grn_0 = new Image();
grn_0.src = "pngs/grn/0.png";
var grn_1 = new Image();
grn_1.src = "pngs/grn/1.png";
var grn_2 = new Image();
grn_2.src = "pngs/grn/2.png";
var grn_3 = new Image();
grn_3.src = "pngs/grn/3.png";
var grn_4 = new Image();
grn_4.src = "pngs/grn/4.png";
var grn_5 = new Image();
grn_5.src = "pngs/grn/5.png";
var grn_6 = new Image();
grn_6.src = "pngs/grn/6.png";
var grn_7 = new Image();
grn_7.src = "pngs/grn/7.png";
var grn_8 = new Image();
grn_8.src = "pngs/grn/8.png";
var grn_9 = new Image();
grn_9.src = "pngs/grn/9.png";
//
var blue_off = new Image();
blue_off.src = "pngs/blue-up.png";
var blue_on = new Image();
blue_on.src = "pngs/blue-dn.png";
var green_off = new Image();
green_off.src = "pngs/green-up.png";
var green_on = new Image();
green_on.src = "pngs/green-dn.png";
var pink_off = new Image();
pink_off.src = "pngs/pink-up.png";
var pink_on = new Image();
pink_on.src = "pngs/pink-dn.png";
//
var out = new Array(8)
out[0]= 0;
out[1]= 0;
out[2]= 0;
out[3]= 0;
out[4]= 0;
out[5]= 0;
out[6]= 0;
out[7]= 0;
//
var bal1 = 0;
var bal2 = 0;
var bal3 = 0;
//
var x=0;
var y=0;
var scr_pos =0;
//
var entry_mode = 0;
//key animation
//
var key_temp;
var key_char;
var entry_str = "";
var entry_len =0;
//
function key_off(new_key){
document.images[new_key].src = blue_off.src;
sound5Play(beep_sound);
}
//
function key_press(sel_key){
entry_mode = 1;
key_temp = sel_key.name;
document.images[key_temp].src = blue_on.src;
window.setTimeout("key_off(key_temp);",200);
key_char = key_temp.charAt(3);
if (key_char=="k"){key_char="000";}
entry_str =  entry_str +  key_char;
entry_len = entry_str.length;
get_grn();
dsp_grn();
}
//
function fun_off(fnew_key){
document.images[fnew_key].src = green_off.src;
sound5Play(beep_sound);
}
//
function fun_press(fsel_key){
key_temp = fsel_key.name;
document.images[key_temp].src = green_on.src;
window.setTimeout("fun_off(key_temp);",200);
key_char = key_temp.charAt(3);
exec_func();
entry_len = entry_str.length;
get_grn();
dsp_grn();
}
//
function mem_off(mnew_key){
document.images[mnew_key].src = pink_off.src;
sound5Play(beep_sound);
}
//
function mem_press(msel_key){
key_temp = msel_key.name;
document.images[key_temp].src = pink_on.src;
window.setTimeout("mem_off(key_temp);",200);
key_char = key_temp.charAt(3);
exec_mem()
}
//
function dsp_orn() {
document.images.orn1.src = "pngs/orn/" + bal1 + ".png";
document.images.orn2.src = "pngs/orn/" + bal2 + ".png";
document.images.orn3.src = "pngs/orn/" + bal3 + ".png";
}
function dsp_grn() {
document.images.grn1.src = "pngs/grn/" + out[0] + ".png";
document.images.grn2.src = "pngs/grn/" + out[1] + ".png";
document.images.grn3.src = "pngs/grn/" + out[2] + ".png";
document.images.grn4.src = "pngs/grn/" + out[3] + ".png";
document.images.grn5.src = "pngs/grn/" + out[4] + ".png";
document.images.grn6.src = "pngs/grn/" + out[5] + ".png";
document.images.grn7.src = "pngs/grn/" + out[6] + ".png";
document.images.grn8.src = "pngs/grn/" + out[7] + ".png";
}
//
function get_grn() {
for (x=0; x<8; x++)
{
if (x<entry_len)
{
out[x]=entry_str.charAt(entry_len -x-1);
}
}
}
//
function exec_func() {
switch (key_char){
case "e":
entry_mode = 0;
bal1 = 1;
bal2 = 2;
bal3 = 3;
entry_str =  entry_str +  key_char;
dsp_orn();
break;
case "n":
//
break;
default:
entry_mode = 1;
entry_str =  entry_str +  key_char;
}
}
//
function exec_mem() {
switch (key_char){
case "z":
entry_str="";
for (x=0; x<8; x++)
{
out[x] =0;
}
dsp_grn();
break;
case "l"://scroll left
if (scr_pos<(entry_len-8)){scr_pos++;}
scroll_grn();
dsp_grn();
break;
case "r":// scroll right
if (scr_pos>0){scr_pos--;}
scroll_grn();
dsp_grn();
break;
break;
}
}
//
function scroll_grn() {
for (x=0; x<8; x++)
{
if ((x+scr_pos)<entry_len)
{
out[x]=entry_str.charAt(entry_len -x-1-scr_pos);
}
else 
{
out[x] =0;
}
}
}